Skip to content

feat: Add reusable API rate limiting helpers#1237

Open
msgem0523 wants to merge 1 commit into
Vets-Who-Code:masterfrom
msgem0523:feature/msgem0523/912-api-rate-limiting-middleware
Open

feat: Add reusable API rate limiting helpers#1237
msgem0523 wants to merge 1 commit into
Vets-Who-Code:masterfrom
msgem0523:feature/msgem0523/912-api-rate-limiting-middleware

Conversation

@msgem0523

Copy link
Copy Markdown
Contributor

Summary

This PR extends the existing rate limiting implementation by adding reusable middleware helpers and configurable rate limit tiers while maintaining backward compatibility with the current checkRateLimit() implementation.

Changes

  • Added configurable RATE_LIMITS presets.
  • Added RateLimitType for standardized rate limit categories.
  • Added applyRateLimit() helper for reusable rate limit enforcement.
  • Added withRateLimit() wrapper for middleware-style usage.
  • Applied rate limiting to the AI chat endpoint using the new helper.

Why

While investigating Issue #912, I found an existing rate-limit.ts implementation already protecting several API routes. Rather than introducing a second implementation, I extended the existing helper to make it reusable across future API endpoints while preserving existing functionality.

Testing

  • Verified the project builds until reaching the existing unrelated TypeScript error in src/pages/admin/courses.tsx:

    • Parameter 'course' implicitly has an 'any' type.
  • Confirmed no additional build errors were introduced by these changes.

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@msgem0523 is attempting to deploy a commit to the vetswhocode-web-app Team on Vercel.

A member of the Team first needs to authorize it.

@msgem0523 msgem0523 requested a review from jeromehardaway July 1, 2026 23:11
@msgem0523 msgem0523 self-assigned this Jul 1, 2026

@jeromehardaway jeromehardaway left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the work to expand the rate limit requests if needed. Also lets verify if chat needs this since its only used with you all and J0D!3 handles that.

Comment thread src/lib/rate-limit.ts
Comment on lines +74 to +79
export const RATE_LIMITS = {
default: { maxRequests: 20, windowMs: 15 * 60 * 1000 },
strict: { maxRequests: 10, windowMs: 15 * 60 * 1000 },
ai: { maxRequests: 5, windowMs: 15 * 60 * 1000 },
search: { maxRequests: 30, windowMs: 15 * 60 * 1000 },
public: { maxRequests: 50, windowMs: 15 * 60 * 1000 },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, why id you choose these parameters for the rate limit?

@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vets-who-code-app Error Error Jul 4, 2026 1:47am

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants